package com.cwj.lab4.查找.散列表;

import com.cwj.lab1.myArrayList;

import java.util.HashMap;

public class TestHashTable {
    public static void main(String[] args) {
        testHash_table(20);
    }
    public static void testHash_table(int num){
        myArrayList<Hash<Integer,Integer>> list=new myArrayList();
        list.addLast(new Hash_table<>());
        list.addLast(new Hash_table_2<>());
        for (int i = 0; i < list.size(); i++) {
            HashMap<Integer,Integer>map=new HashMap<>();
            choose(list.get(i),map,num);
        }

    }
    static private void choose(Hash<Integer,Integer> table,HashMap<Integer,Integer>map,int num){
        System.out.println(table.getClass().getSimpleName());
        int p=table.getP();
        System.out.print("p=");
        System.out.println(p);
        for(int i=0;i<num;i+=1){
            int ind=i>10?1/*(int)(Math.random()*2)*/:0;
            int key=(int)(Math.random()*10);//注意是不想将key设置过大，为了set三种情况考虑（覆盖，不冲突，冲突）
            int data=(int)(Math.random()*10);
            switch (ind){
                case 0:
                    System.out.println("map.set("+key+","+data+")一次");
                    table.set(key,data);
                    map.put(key,data);
                    break;
                case 1:
//                    System.out.println("map.set("+key+","+data+")一次");
                    System.out.print("java标准库.find("+key+")="+map.get(key));

                    System.out.println("\t测试类table.find("+key+")="+table.find(key));

                    break;
            }
        }
    }
}
